﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Agile.Engine.Xml
{
    public class XmlResourceFactory : XmlResource
    {
        protected override void PaserResource(System.IO.Stream stream)
        {
            System.Xml.Linq.XElement root = System.Xml.Linq.XElement.Load(stream);
            foreach (var el in root.Elements("data").AsParallel())
            {
                //解析类型
                var type = el.Attribute("type").Value;

                //创建实例
                var instance = Agile.Engine.Utils.ReflectUtils.Instance(type) as XmlResource;
                instance.ConfigUri =
                    Agile.Engine.Utils.VelocityUtils.MergeString(el.Attribute("value").Value, ObjectContext.Environment.Registry);

                this[el.Attribute("key").Value] = instance;
            }
        }

    }
}
